package com.xiaode.controller.app.task.example;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.anotation.BooleanV;
import com.xiaode.common.anotation.JSONArrayString;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;
import javax.validation.constraints.Size;

@Path("/example")
@Api("重要他人任务模块")
@EnableCORS
public class ExampleController extends Controller {
	
    @Inject
    ExampleService service;


    @ApiOper("发表我的重要他人任务完成情况")
    public void commitExampleActivity(
    		@Size @ApiPara(value = "taskAlignmentId", notes = "任务对齐id") Integer taskAlignmentId,
    		@Size(max = 500) @ApiPara(value = "content", notes = "任务内容") String content,
    		@JSONArrayString @ApiPara(value = "files", notes = "files[{type:xxx,url:xxx},{type:xxx,url:xxx}]") String files,
    		@JSONArrayString @ApiPara(value = "keyResults", notes = "keyResults[{content:XXX,files:{type:xxx,url:xxx},{type:xxx,url:xxx}}]") String keyResults) throws Exception {
    	Integer accountId = getAttr("accountId");
    	Integer userId = getAttr("userId");
        Ret ret = service.commitExampleActivity(accountId, userId, taskAlignmentId, content, keyResults, files);
        renderJson(ret);
    }

    @ApiOper("查询我的重要他人任务")
    public void findExampleActivetyPage(
            @ApiPara(value = "accountId", notes = "账号id（不传代表查询自己的）") Integer accountId,
    		@Size @ApiPara(value = "page", notes = "当前页") Integer page,
    		@Size @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception {
    	Integer accountIdMy = getAttr("accountId");
        Ret ret = service.findExampleActivetyPage(accountId, accountIdMy, page, limit);
        renderJson(ret);
    }
    
    @ApiOper("重要他人任务审核")
    public void examine(@Size @ApiPara(value = "taskId", notes = "任务Id") Integer taskId,
            @Size(min = 1, max = 10) @ApiPara(value = "score", notes = "任务得分") Integer score,
            @ApiPara(value = "content", notes = "评论内容") String content,
            @BooleanV @ApiPara(value = "addTrajectory",notes = "是否加入轨迹图")Boolean addTrajectory) throws Exception {
    	Integer accountId = getAttr("accountId");
    	Integer userType = getAttr("userType");
    	Ret ret = service.examine(accountId, userType, taskId, score, content, addTrajectory);
    	renderJson(ret);
    }

}
